define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hotel/hotelorderinvoice/index' + location.search,
                    add_url: 'hotel/hotelorderinvoice/add',
                    //edit_url: 'hotel/hotelorderinvoice/edit',
                    del_url: 'hotel/hotelorderinvoice/del',
                    multi_url: 'hotel/hotelorderinvoice/multi',
                    import_url: 'hotel/hotelorderinvoice/import',
                    table: 'hotel_order_invoice',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'title.taxid', title: __('Title.taxid'), operate: 'LIKE'},
                        {field: 'title.invoice_title', title: __('Title.invoice_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title.mobile', title: __('Title.mobile'), operate: 'LIKE'},
                        {field: 'title.email', title: __('Title.email'), operate: 'LIKE'},
                        {field: 'status', title: __('状态'), formatter: Table.api.formatter.status, searchList: { 0: __('开票中'), 1: __('已开票'), 2: __('已驳回')}},
                        {
                            field: 'operate', title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'audit',
                                    text: __('确认开票'),
                                    confirm:'确认审核通过该岗位吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'hotel/hotelorderinvoice/pass',
                                    visible:function(row){
                                        if(row.status == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('驳回'),
                                    classname: 'btn btn-info btn-xs btn-danger btn-dialog',
                                    url: 'hotel/hotelorderinvoice/refuse',
                                    refresh:true,
                                    visible:function(row){
                                        if(row.status == 0){
                                            return true;
                                        }
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
